<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Title</title>
    <style>
      .demo {
        background-color: skyblue;
      }
    </style>
  </head>
  <body>
    <button id="btn">点我创建一个输入框</button>
    <script>
      const btn = document.getElementById("btn");
      btn.onclick = () => {
        const input = document.createElement("input");

        // input.focus();// 不奏效
        // input.parentElement.style.backgroundColor = 'orange';// 报错

        input.className = "demo"; // 奏效
        input.value = "99"; // 奏效
        // input.onclick = () => {
        //   alert(1);
        // }; // 奏效

        document.body.appendChild(input);
        input.focus(); // 奏效
        input.parentElement.style.backgroundColor = "orange";
      };
    </script>
  </body>
</html>
